﻿using GameLibrary.Model;
using GameLibrary.Model.Core;
using GameLibrary.Model.Enums;
using G.Runtime;

namespace GameDesigner.Source.Test
{
    public class Dual
    {
        
        public static void Build(GameDef game)
        {
            game.Name = "Dual";
            {
                GameElementDef element = GameDefFactory.Factory.CreateElement(
                    game, new GameLocation(0, 0));
                element.MoveStratagy = MoveStratagyEnum.RIGHT;
                element.Player = "Player1";
                game.GameElementDefs.Add(element);
                element.GameValueDefs.Add("Chance", System.TypeCode.Int32);
            }
            {
                GameElementDef element = GameDefFactory.Factory.CreateElement(
                    game, new GameLocation(9, 0));
                element.MoveStratagy = MoveStratagyEnum.LEFT;
                element.Player = "Player2";
                game.GameElementDefs.Add(element);
                element.GameValueDefs.Add("Chance", System.TypeCode.Int32);
            }
            {
                GameTaskDef task = GameDefFactory.Factory.CreateTask(game);
                game.GameTaskDefs.Add(task);
                task.Name = "Shoot";
                task.GameScriptDef.Text = @"
public class ScriptClass 
{
    private G.Runtime.GameTask _Subject;

    public ScriptClass(G.Runtime.GameTask subject)
    {
        _Subject = subject;
        _Subject.Triggers.TriggerEvent += OnTriggerEvent;
    }

    void OnTriggerEvent(G.Runtime.GameElement element)
    {
    	  G.Runtime.IntGameValue v = (G.Runtime.IntGameValue)
            element.GameValues[""Chance""];
         int r = new System.Random().Next(5);
         if (r < v.Value)
         {
            _Subject.Game.Globals.FireMessage(""HIT"");
         }
         else
         {
            _Subject.Game.Globals.FireMessage(""MISS"");
         }
    }
}
";
            }
            {
                game.GameElementDefs.GameScriptDef.Text = @"
public class GameElementsDefs_Script
{
    private G.Runtime.GameElements _Subject;

    public GameElementsDefs_Script(G.Runtime.GameElements subject)
    {
        _Subject = subject;
        _Subject.Triggers.ConsumeEvent += OnConsumeEvent;
        _Subject.Triggers.MovedEvent += OnMovedEvent;
    }

    void OnConsumeEvent(G.Runtime.GameElement consumer, G.Runtime.GameElement consumee)
    {
        consumer.GameValues.Add(consumee.GameValues);
        consumer.Location = consumee.Location;
    }
    
    void OnMovedEvent(G.Runtime.GameElement element)
    {
    	G.Runtime.IntGameValue v = (G.Runtime.IntGameValue)
            element.GameValues[""Chance""];
    	v.Value += 1;
    }
}
";
                
                game.GamePlayerDefs.GameScriptDef.Text = @"
public class GamePlayerDefs_Script
{
    private G.Runtime.GamePlayers _Subject;

    public GamePlayerDefs_Script(G.Runtime.GamePlayers subject)
    {
        _Subject = subject;
        _Subject.Triggers.EndOfTurnEvent += OnEndOfTurnEvent;
    }

    void OnEndOfTurnEvent(G.Runtime.GameEvent turnEvent)
    {
    	 turnEvent.FireInvoke();
    }

}
";
                
            }
        }
        
    }
}
